package com.zh.onlineexam.config;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.WriteConverterContext;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.data.WriteCellData;

/**
 * @className IsRightConverter
 * @Description TODO
 * @Auther 29934
 * @Date 2022/9/13 22:23
 * @Version 1.0
 **/
public class IsRightConverter implements Converter<Integer> {
    @Override
    public Class supportJavaTypeKey() {
        return Integer.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }


    @Override
    public WriteCellData<?> convertToExcelData(WriteConverterContext<Integer> context) throws Exception {
        //对象属性转CellData
        Integer cellValue = context.getValue();
        if (cellValue == null) {
            return new WriteCellData<>("");
        }
        if (cellValue == 0) {
            return new WriteCellData<>("正确");
        } else if (cellValue == 1) {
            return new WriteCellData<>("错误");
        } else {
            return new WriteCellData<>("");
        }
    }
}
